// |**| Opcon|OperationMango|**|Opcon|OperationMango|**|
// |**| Source Code for the FPS Operation Mango     |**|
// |**| Opcon|OperationMango|**|Opcon|OperationMango|**|

using System;
using System.IO;

namespace OperationMango
{


	public class FileWatcher
	{
		
		/// <summary>
		/// Get property for Path
		/// </summary>
		public string Path
		{
			get
			{
				return path;
			}
		}
		protected string path;
		
		/// <summary>
		/// Get Property for Filter
		/// </summary>
		public string Filter
		{
			get
			{
				return filter;
			}
		}
		protected string filter;
		
		protected FileChangeHandler m_FileChangeHandler;
		protected FileSystemWatcher m_FileSystemWatcher;
		
//------------------------------------------------------------------------------------------------		
		public FileWatcher (string p, string f)
		{
			path = p;
			filter = f;
			m_FileSystemWatcher = new FileSystemWatcher(Path, Filter);
			SetupFileChangeHandler ();
		}
		
		public FileWatcher (string p)
		{
			path = p;
			m_FileSystemWatcher = new FileSystemWatcher(Path);
			SetupFileChangeHandler ();
		}
		
		public FileWatcher ()
		{
			m_FileSystemWatcher = new FileSystemWatcher();
			SetupFileChangeHandler ();
		}
//------------------------------------------------------------------------------------------------
		protected void SetupFileChangeHandler ()
		{
			m_FileChangeHandler = new FileChangeHandler();
			m_FileSystemWatcher.Changed += delegate(object sender, FileSystemEventArgs e) 
			{
				CallFileChangeHandler(e);
			};
			
			m_FileSystemWatcher.EnableRaisingEvents = true;

		}
//------------------------------------------------------------------------------------------------
		public void SetFilter(string f)
		{
			filter = f;
			m_FileSystemWatcher.Filter = Filter;
		}
		
		public void SetDirectory(string p)
		{
			path = p;
			m_FileSystemWatcher.Path = Path;
		}
		
//------------------------------------------------------------------------------------------------
		protected void CallFileChangeHandler(FileSystemEventArgs e)
		{
			m_FileChangeHandler.FileChanged(e);
		}
	}
}
